<template>
  <div class="ds-left">
    <div class="eq-left-top">
      <div class="eq-left-top-title">
        <img src="../../../assets/images/home-page/eq-right.png" alt="" />
        设备树
      </div>
      <div class="eq-left-top-content">
        <!-- <div class="eq-left-top-c-seach">
          <input type="text" v-model="searchQuery" placeholder="搜索" />
        </div> -->
        <div class="eq-left-top-c-tree">
          <el-tree :data="treeList" :props="defaultProps" @node-click="handleNodeClick"></el-tree>
        </div>
      </div>
    </div>
    <div class="eq-left-bottom">
      <div class="eq-left-bottom-title">
        <img src="../../../assets/images/home-page/eq-right.png" alt="" />
        主接线图
      </div>
      <div class="eq-left-bottom-item">
        <div class="eq-left-bottom-i-svg">
          <img class="fd-svg" @click="handleClick" src="../../../assets/images/home-page/fd.png" alt="" srcset="" />
          <div class="eq-left-svg">
            <img src="../../../assets/images/home-page/svg-bg.png" alt="" srcset="" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
  import { tree } from '@/api/auth/ledger.js';
  import { onMounted } from 'vue';
  import { getModelByName } from '../../../utils/ue.js';

  const treeList = ref([]);
  const emit = defineEmits();
  const defaultProps = {
    children: 'children',
    label: 'deviceName'
  };
  // 搜索框的值
  const searchQuery = ref('');
  const filteredData = computed(() => {
    return treeList.value.filter((item) => item.deviceName.toLowerCase().includes(searchQuery.value.toLowerCase()));
  });
  onMounted(() => {
    getTreeList();
  });
  const getTreeList = () => {
    tree().then((res) => {
      treeList.value = res.data;
      console.log('res', res);
    });
  };
  const handleNodeClick = (data) => {
    console.log(data.deviceName);
    getModelByName('DS___278_2').then((res) => {
      console.log('res777', res);
    });
    emit('treeNodeClick', data);
  };
  function handleClick(event) {
    emit('handleClick');
    // 这里可以访问原生点击事件对象 event
    // 执行进一步的逻辑处理，例如调用其他方法或修改数据
  }
</script>

<style lang="scss" scoped>
  .ds-left {
    width: 360px;
    position: absolute;
    top: 120px;
    left: 18px;
    z-index: 999;
    .eq-left-top {
      width: 100%;
      height: 48.5vh;
      background: rgba(5, 30, 67, 0.6);
      .eq-left-top-title {
        width: 100%;
        height: 33px;
        background: rgba(10, 39, 82, 1);
        display: flex;
        align-items: center;
        color: #fff;
        font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 16px;
        img {
          width: 20px;
          height: 21px;
          margin: 0 5px 0 10px;
        }
      }
      .eq-left-top-content {
        padding: 10px 0;
        // height: 504px;

        .eq-left-top-c-seach {
          width: 340px;
          height: 38px;
          background-image: url('../../../assets/images/home-page/seach-bg.png');
          background-size: 100% 100%;
          margin: 0 auto;
          line-height: 38px;
          input {
            background: transparent;
            width: 60%;
            height: 25px;
            margin-left: 15px;
            color: #fff;
            outline: none;
            border: none;
          }
        }
        .eq-left-top-c-tree {
          width: 90%;
          margin: 10px auto 0 auto;
        }
      }
    }
    .eq-left-bottom {
      height: 30vh;
      width: 100%;
      // background: rgba(5, 30, 67, 0.6);
      .eq-left-bottom-title {
        width: 100%;
        height: 33px;
        background: rgba(10, 39, 82, 1);
        display: flex;
        align-items: center;
        color: #fff;
        font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 16px;
        margin-top: 13px;
        img {
          width: 20px;
          height: 21px;
          margin: 0 5px 0 10px;
        }
      }
      .eq-left-bottom-item {
        width: 360px;

        // padding: 30px 0 40px 0;
        .eq-left-bottom-i-svg {
          width: 360px;
          height: 26vh;
          margin: 0 auto;
          position: relative;
          .fd-svg {
            width: 25px;
            height: 25px;
            position: absolute;
            top: 0;
            right: 0;
            // transform: translate(-50%, -50%);
            cursor: pointer;
          }
          .eq-left-svg {
            width: 100%;
            height: 100%;
            img {
              width: 100%;
              height: 100%;
              cursor: pointer;
            }
          }
        }
      }
    }
  }
  :deep(.el-tree) {
    background-color: transparent !important;
    height: 38vh;
    overflow-y: scroll;
    .el-tree-node__label {
      font-size: 12px;
      font-family:
        PingFangSC,
        PingFang SC;
      color: #ffffff;
    }
  }
  :deep(.el-tree-node__content:hover) {
    // width: 280px !important;
    // background-color: transparent !important;
    // color: red !important;
    // height: 30px !important;
    background-color: transparent !important;
    // height: 30px !important;
    background-image: url('../../../assets/images/home-page/tree-bg.png') !important;
    background-size: 100% 100% !important;
  }
  :deep(.el-tree-node__expand-icon) {
    color: #ffffff !important;
  }

  :deep(.el-tree-node:focus > .el-tree-node__content) {
    /* background-color: #214a37 !important; */
    background-color: transparent !important;
    // height: 30px !important;
    background-image: url('../../../assets/images/home-page/tree-bg.png') !important;
    background-size: 100% 100% !important;
  }
  // :deep(.el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content) {
  //   background-color: transparent !important;
  // }
  /* 如果你想要改变特定节点的背景色 */
  // .eq-left-top-c-tree .el-tree .el-tree-node.is-expanded {
  //   background-color: #f0f0f0; /* 展开节点的颜色 */
  // }
</style>
